<?php

/*
 * CopyRight  : (C)2012-2099 HaoTeam Inc.
 * Document   : Article.php
 * Created on : 2022-12-22 17:43:29
 * Author     : Tiger <1192851302@qq.com>
 * Description: This is NOT a freeware, use is subject to license terms.
 *              这即使是一个免费软件,使用时也请遵守许可证条款,得到当时人书面许可.
 *              未经书面许可,不得翻版,翻版必究;版权归属 HaoTeam Inc;
 */

namespace app\api\controller;

use app\Request;
use haoteam\service\UtilService;
use app\models\Article as ArticleModel;

/**
 * @title 内容文章
 * Class Article
 * Tiger <1192851302@qq.com> 2022-12-22 17:43:29
 */
class Article {

    /**
     * @title 内容列表
     * @author Tiger <1192851302@qq.com>
     * @url /api/article/list
     * @method GET
     * @param name:id type:string require:1 default:0 other:'' desc:文章分类ID
     * @return array:数组值#
     */
    public function list(Request $request) {
        [$category_id, $search] = UtilService::postMore([
                    ['id', 0],
                    ['search', '']
                        ], $request, true);
        $where = [];
        if ($category_id) {
            $where = compact('category_id');
        }
        if (!empty($search)) {
            $where['search'] = $search;
        }
        $items = ArticleModel::getList($where);
        return app('json')->successful($items);
    }

    /**
     * @title 内容详情
     * @author Tiger <1192851302@qq.com>
     * @url /api/article/detail
     * @method GET
     * @param name:id type:string require:1 default: other:'' desc:文章ID
     * @return array:数组值#
     */
    public function detail(Request $request) {
        [$id] = UtilService::getMore(['id'], $request, true);
        $items = ArticleModel::getInfo($id);
        return app('json')->successful(compact('items'));
    }

}
